package com.yaoli.niuke;

import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;

/**
 * Created by will on 2017/5/10.
 */
public class _012_Test {
    public int FirstNotRepeatingChar(String str) {
        Map<Character,Integer> map = new LinkedHashMap<Character, Integer>();
        for(int i = 0 ; i < str.length(); i++){
            if(!map.containsKey(str.charAt(i))){
                map.put(str.charAt(i),1);
            }else{
                map.put(str.charAt(i),map.get(str.charAt(i))+1);
            }

        }

        for(Character i : map.keySet()){
            if(map.get(i) == 1){
                for(int j = 0 ; j < str.length(); j++){
                    if(str.charAt(j) == i){
                        return j;
                    }
                }
                break;
            }
        }

        return -1;
    }
}
